<?php

	// TITLE: Project AUTO MODEL
	// FILE: scaffolding/model/project.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createProject = function($con, $project) {
		$sql = 'INSERT INTO project (id, is_active, address_id, municipality_id, sponser_id, date_of_origin, start_date, estimated_completion_date, actual_completion_date, description, extimated_valutation, estimated_purchase, estimated_rehab, estimated_pre_cq, actual_pre_acq, estimated_sponser_value, estimated_donation_value, estimated_sell_price, estimated_volunteer_hours, estimated_purchase_cost, actual_purchase_cost, materials_budger, labor_budget, subcontract_budget, indirect_allocation_budget, buyer_hours_required, estimated_selling_price, actual_appraisal_value, actual_sell_price) VALUES (';
		$sql .= $project->getId() . ', ';
		$sql .= $project->getIsActive() . ', ';
		$sql .= $project->getAddressId() . ', ';
		$sql .= $project->getMunicipalityId() . ', ';
		$sql .= $project->getSponserId() . ', ';
		$sql .= $project->getDateOfOrigin() . ', ';
		$sql .= $project->getStartDate() . ', ';
		$sql .= $project->getEstimatedCompletionDate() . ', ';
		$sql .= $project->getActualCompletionDate() . ', ';
		$sql .= $project->getDescription() . ', ';
		$sql .= $project->getExtimatedValutation() . ', ';
		$sql .= $project->getEstimatedPurchase() . ', ';
		$sql .= $project->getEstimatedRehab() . ', ';
		$sql .= $project->getEstimatedPreCq() . ', ';
		$sql .= $project->getActualPreAcq() . ', ';
		$sql .= $project->getEstimatedSponserValue() . ', ';
		$sql .= $project->getEstimatedDonationValue() . ', ';
		$sql .= $project->getEstimatedSellPrice() . ', ';
		$sql .= $project->getEstimatedVolunteerHours() . ', ';
		$sql .= $project->getEstimatedPurchaseCost() . ', ';
		$sql .= $project->getActualPurchaseCost() . ', ';
		$sql .= $project->getMaterialsBudger() . ', ';
		$sql .= $project->getLaborBudget() . ', ';
		$sql .= $project->getSubcontractBudget() . ', ';
		$sql .= $project->getIndirectAllocationBudget() . ', ';
		$sql .= $project->getBuyerHoursRequired() . ', ';
		$sql .= $project->getEstimatedSellingPrice() . ', ';
		$sql .= $project->getActualAppraisalValue() . ', ';
		$sql .= $project->getActualSellPrice() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readProject = function($con, $id) {
		$sql = 'SELECT * FROM project WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$project = new Project();
			$project->setId(result[0]);
			$project->setIsActive(result[1]);
			$project->setAddressId($dbio->select($readAddress(result[2])));
			$project->setMunicipalityId($dbio->select($readMunicipality(result[3])));
			$project->setSponserId($dbio->select($readSponser(result[4])));
			$project->setDateOfOrigin(result[5]);
			$project->setStartDate(result[6]);
			$project->setEstimatedCompletionDate(result[7]);
			$project->setActualCompletionDate(result[8]);
			$project->setDescription(result[9]);
			$project->setExtimatedValutation(result[10]);
			$project->setEstimatedPurchase(result[11]);
			$project->setEstimatedRehab(result[12]);
			$project->setEstimatedPreCq(result[13]);
			$project->setActualPreAcq(result[14]);
			$project->setEstimatedSponserValue(result[15]);
			$project->setEstimatedDonationValue(result[16]);
			$project->setEstimatedSellPrice(result[17]);
			$project->setEstimatedVolunteerHours(result[18]);
			$project->setEstimatedPurchaseCost(result[19]);
			$project->setActualPurchaseCost(result[20]);
			$project->setMaterialsBudger(result[21]);
			$project->setLaborBudget(result[22]);
			$project->setSubcontractBudget(result[23]);
			$project->setIndirectAllocationBudget(result[24]);
			$project->setBuyerHoursRequired(result[25]);
			$project->setEstimatedSellingPrice(result[26]);
			$project->setActualAppraisalValue(result[27]);
			$project->setActualSellPrice(result[28]);
		} else {
			$project = false;
		}
		return $project;
	};

	$updateProject = function($con, $project) {
		$sql = 'UPDATE project SET ';
		$sql .= 'id = ' . $project->getId() . ', ';
		$sql .= 'is_active = ' . $project->getIsActive() . ', ';
		$sql .= 'address_id = ' . $project->getAddressId() . ', ';
		$sql .= 'municipality_id = ' . $project->getMunicipalityId() . ', ';
		$sql .= 'sponser_id = ' . $project->getSponserId() . ', ';
		$sql .= 'date_of_origin = ' . $project->getDateOfOrigin() . ', ';
		$sql .= 'start_date = ' . $project->getStartDate() . ', ';
		$sql .= 'estimated_completion_date = ' . $project->getEstimatedCompletionDate() . ', ';
		$sql .= 'actual_completion_date = ' . $project->getActualCompletionDate() . ', ';
		$sql .= 'description = ' . $project->getDescription() . ', ';
		$sql .= 'extimated_valutation = ' . $project->getExtimatedValutation() . ', ';
		$sql .= 'estimated_purchase = ' . $project->getEstimatedPurchase() . ', ';
		$sql .= 'estimated_rehab = ' . $project->getEstimatedRehab() . ', ';
		$sql .= 'estimated_pre_cq = ' . $project->getEstimatedPreCq() . ', ';
		$sql .= 'actual_pre_acq = ' . $project->getActualPreAcq() . ', ';
		$sql .= 'estimated_sponser_value = ' . $project->getEstimatedSponserValue() . ', ';
		$sql .= 'estimated_donation_value = ' . $project->getEstimatedDonationValue() . ', ';
		$sql .= 'estimated_sell_price = ' . $project->getEstimatedSellPrice() . ', ';
		$sql .= 'estimated_volunteer_hours = ' . $project->getEstimatedVolunteerHours() . ', ';
		$sql .= 'estimated_purchase_cost = ' . $project->getEstimatedPurchaseCost() . ', ';
		$sql .= 'actual_purchase_cost = ' . $project->getActualPurchaseCost() . ', ';
		$sql .= 'materials_budger = ' . $project->getMaterialsBudger() . ', ';
		$sql .= 'labor_budget = ' . $project->getLaborBudget() . ', ';
		$sql .= 'subcontract_budget = ' . $project->getSubcontractBudget() . ', ';
		$sql .= 'indirect_allocation_budget = ' . $project->getIndirectAllocationBudget() . ', ';
		$sql .= 'buyer_hours_required = ' . $project->getBuyerHoursRequired() . ', ';
		$sql .= 'estimated_selling_price = ' . $project->getEstimatedSellingPrice() . ', ';
		$sql .= 'actual_appraisal_value = ' . $project->getActualAppraisalValue() . ', ';
		$sql .= 'actual_sell_price = ' . $project->getActualSellPrice() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteProject = function($con, $id) {
		$sql = 'DELETE FROM project WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listProject = function($con) {
		$sql = 'SELECT * FROM project';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$projects = array();
			while ($result = mysqli_fetch_array($results)) {
				$project = new Project();
				$project->setId(result[0]);
				$project->setIsActive(result[1]);
				$project->setAddressId($dbio->select($readAddress(result[2])));
				$project->setMunicipalityId($dbio->select($readMunicipality(result[3])));
				$project->setSponserId($dbio->select($readSponser(result[4])));
				$project->setDateOfOrigin(result[5]);
				$project->setStartDate(result[6]);
				$project->setEstimatedCompletionDate(result[7]);
				$project->setActualCompletionDate(result[8]);
				$project->setDescription(result[9]);
				$project->setExtimatedValutation(result[10]);
				$project->setEstimatedPurchase(result[11]);
				$project->setEstimatedRehab(result[12]);
				$project->setEstimatedPreCq(result[13]);
				$project->setActualPreAcq(result[14]);
				$project->setEstimatedSponserValue(result[15]);
				$project->setEstimatedDonationValue(result[16]);
				$project->setEstimatedSellPrice(result[17]);
				$project->setEstimatedVolunteerHours(result[18]);
				$project->setEstimatedPurchaseCost(result[19]);
				$project->setActualPurchaseCost(result[20]);
				$project->setMaterialsBudger(result[21]);
				$project->setLaborBudget(result[22]);
				$project->setSubcontractBudget(result[23]);
				$project->setIndirectAllocationBudget(result[24]);
				$project->setBuyerHoursRequired(result[25]);
				$project->setEstimatedSellingPrice(result[26]);
				$project->setActualAppraisalValue(result[27]);
				$project->setActualSellPrice(result[28]);
				$projects[] = project;
			}// end while
		} else {
			$projects = false;
		}
		return $projects;
	};

